<?php

namespace App\Http\Controllers\Test;

use App\Http\Controllers\Controller;
use App\Service\Email;
use Illuminate\Support\Facades\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;


class MailController extends Controller
{
    // 发送邮件测试
    public function initialize()
    {
        parent::initialize();
    }

    // 发送邮件
    public function send2()
    {
        $mail   = '914432635@qq.com';
        $mail   = '23231590@qq.com';
        $code   = rand(1000, 9999);
        $attach = 'D:/phpSite/slcm/option/public/favicon.ico'; // 附件
        $attach = ''; // 附件
        $data   = ['code' => $code];
        $title = '易见股份'.date("Y-m-d").'舆情汇总';

        $email = new Email();
        $res   = $email->send($mail,$title, $data, $attach);
        if($res === false){
            return ["code" => 0, "msg" => "发送邮件失败"];
        }

        return ["code" => 1, "msg" => "success"];
    }

    // 发送的数据：获取昨天采集的数据
    protected function getLists()
    {

    }

    // 测试
    // http://www.option.com/test/mail/send
    // 深蓝汇发送邮件
    // lisen1004@qq.com
    // SClzliuxu231590
    // 授权码（在qq邮箱中设置获取）
    // fekerjeqpfiobhga
    public function send()
    {
        $email = '23231590@qq.com';
        $email = '914432635@qq.com';
        $code  = rand(1000, 9999);

        //使用blade模板发送(引用的模板)
        // Mail::send(模板文件, [参数], function($message) use ($email) {});
        Mail::send('emails.email', ['code' => $code], function($message) use ($email) {
            $message->to($email)->subject(date("Y-m-d").'舆情汇');

            // 发送附件：成功
            $message->to($email)->subject('舆情汇')->attach('D:/phpSite/slcm/option/public/favicon.ico');

            // 发送附件：执行失败
            // $message->to($email)->subject('深蓝汇')->attachFromStorage('D:/phpSite/slcm/option/public/favicon.ico', 'name.pdf', ['mime' => 'application/pdf']);
            // 发送附件
            // ->attachFromStorage('/path/to/file');
            // attachFromStorage 方法的第二个和第三个参数指定文件的附件名称和其他选项
            //->attachFromStorage('/path/to/file', 'name.pdf', ['mime' => 'application/pdf']);
        });
        if(Mail::failures()){
            return ["code" => 0, "msg" => "error"];
        }

        return ["code" => 1, "msg" => "success"];
    }

}



